package com.wu.controller;

import com.wu.mapper.OrderMapper;
import com.wu.pojo.Order;
import com.wu.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class orderController {


    @Autowired
    private OrderMapper orderMapper;

    @PostMapping("/save")
    public void save(@RequestBody Order order){
        orderMapper.save(order);
    }


    @GetMapping("/findallByUid/{page}/{limit}/{uid}")
    public OrderVo findAllByUid(@PathVariable("page") int page, @PathVariable("limit") int limit, @PathVariable("uid")long uid){
        return new OrderVo().setCode(0).setMsg("").setCount(orderMapper.countByUid(uid)).setData(orderMapper.findallByUid(page, limit, uid));
    }

    @GetMapping("/findAll/{page}/{limit}")
    public List<Order> findAll(@PathVariable("page") int page, @PathVariable("limit") int limit){
        return orderMapper.findAll(page, limit);
    }

    @GetMapping("/updateState/{id}")
    public void updata(@PathVariable("id")long id){
        orderMapper.updateState(id);
    }

    @GetMapping("/count")
    public int count(){
        return orderMapper.count();
    }



}
